package com.zqh.volatileDemo.CAS;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 曾庆红
 * {@code @date} 2023-10-12 11:11
 */

public class T1 {
    AtomicInteger count = new AtomicInteger(0);
    void m(){
        for(int i = 0; i < 10000; i++){
            count.incrementAndGet();
        }
    }
    public static void main(String[] args){
        T1 t = new T1();
        List<Thread> threads = new ArrayList<>();
        for(int i = 0; i< 10 ;i++){
            threads.add(new Thread(t::m,"Thread-"+i));
        }
        threads.forEach(Thread::start);
        threads.forEach((o)->{
            try {
                o.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        System.out.println(t.count);
    }
}
